package GUI;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Text3 extends JFrame implements ActionListener {
   private JTextField textField = new JTextField("0");
    public Text3(){
        this.setLayout(null);

        JButton btn1 = new JButton("+");
        btn1.setBounds(0,0,50,20);
        this.add(btn1);
        btn1.addActionListener(this);

        textField.setBounds(50,0,100,20);
        this.add(textField);
        textField.addActionListener(this);

        JButton btn2 = new JButton("-");
        btn2.setBounds(150,0,50,20);
        this.add(btn2);
        btn2.addActionListener(this);

        this.setSize(800, 600);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    public static void main(String[] args) {
        new Text3();

    }

    @Override
    public void actionPerformed(ActionEvent e) {
       String a= textField.getText();
       int b=Integer.parseInt(a);
        if(e.getActionCommand().equals("+")){
            b++;
        }else if (e.getActionCommand().equals("-")){
            b--;
        }
        String c=String.valueOf(b);
        textField.setText(c);
    }
}
